<template>
  <view class="page">
    <Header></Header>
    <view class="main_container">
      <view class="main_content">
        <Breadcrumb :text="'个人评测-课堂作业-句子听选'"> </Breadcrumb>
        <view class="content">
          <SentenceTest
            v-if="sentenceList.length > 0"
            :type="type"
            :sentenceList="sentenceList"
            :bookInfo="bookChapter"
            @back="handleBack"
            @save="handleSave"
          ></SentenceTest>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import {
  findSentenceByChapterId,
  classworkListeningSave,
} from "@/api/classWork";
export default {
  components: {},
  onLoad(option) {
    this.chapterId = option.chapterId;
    this.init();
  },
  data() {
    return {
      type: 1,
      chapterId: "",
      sentenceList: [],
      bookInfo: null,
    };
  },
  methods: {
    init() {
      let params = {
        chapterId: this.chapterId,
        type: this.type,
      };
      findSentenceByChapterId(params).then((res) => {
        this.sentenceList = res.data.sentences;
        this.bookChapter = res.data.bookChapter;
      });
    },
    handleSave(score) {
      let params = {
        chapterId: this.chapterId,
        score: score,
        type: this.type,
        testFlag: true,
      };
      classworkListeningSave(params);
    },
    handleBack() {
      uni.redirectTo({
        url: "/pages/classWork/classWork",
      });
    },
  },
};
</script>

<style lang="scss" scoped>
@import "./classWorkChoiceAfterSchool";
</style>
